<?php

namespace app\admin\validate\marketing;

use app\admin\validate\Validates;

class Coupons extends Validates
{
    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...]
     *
     * @var array
     */	
	protected $rule = [
        'ids|标识' => 'require|array',
        'id|参数' => 'require|>:0',
        'use_date|可用时间' => 'date',
        'type|使用范围' => '>=:0',
        'price|金额' => 'require|float',
        'start_date|可用时间' => 'require|date',
        'end_date|过期时间' => 'require|date',
    ];
    
    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'
     *
     * @var array
     */	
    protected $message = [];

    /**
     * 定义场景
     * @var []
     */
    protected $scene = [
        'index' => ['name','cycle','type'],
        'delete' => ['id'],
        'destory' => ['ids'],
    ];

    /**
     * 定义新增场景验证
     * @return $this
     */
    public function sceneCreate()
    {
        return $this->only(['type','start_date','end_date','price'])
            ->remove('type', '>=')
            ->append('type', 'require|array');
    }

    /**
     * 定义编辑场景验证
     * @return $this
     */
    public function sceneUpdate()
    {
        return $this->only(['type','start_date','end_date','price'])
            ->remove('type', '>=')
            ->append('type', 'require|array');
    }

}
